<template>
	<view>
		<view class="main-title">您为什么取消订单</view>
		<view class="tip-title">请告知我们取消原因，我们将努力改善</view>
		<view class="cause-box">
			<view class="flex justify-between align-center item-box"
				v-for="(item,index) in dict.type.cancel_reservation" :key="index" @click="selectIndex=index">
				<view>{{item.label}}</view>
				<image class="select-img" v-if="selectIndex==index"
					src="https://saas-v5.oss-cn-guangzhou.aliyuncs.com/saas-admin/druid/mpimg/cause_.png" mode="">
				</image>
				<image class="select-img" v-else
					src="https://saas-v5.oss-cn-guangzhou.aliyuncs.com/saas-admin/druid/mpimg/cause_no.png" mode="">
				</image>
			</view>
		</view>
		<view class="bottom-box">
			<button class="btn" @click="cancel">提交</button>
		</view>

	</view>
</template>

<script>
	import {
		computeRefund,
		cancelReservation
	} from '@/api/order';
	export default {
		dicts: ["cancel_reservation"],
		data() {
			return {
				orderId: '',
				selectIndex: -1
			}
		},
		onLoad(opt) {
			this.orderId = opt.orderId

		},
		methods: {
			cancel() {
				if (this.selectIndex == -1) {
					uni.showToast({
						title: '请选择取消原因',
						icon: 'none'
					})
					return
				}
				let data = {
					orderId: this.orderId,
					recordReason: this.dict.type.cancel_reservation[this.selectIndex].label
				}
				uni.showModal({
					title: '',
					content: '确认后，将未您进行退款审核，审核通过后预计3个工作日内退回原支付渠道，是否提交？',
					confirmColor:'#FF7947',
					success: (res) => {
						if (res.confirm) {
							cancelReservation(data).then(res => {
                if(res.code==200){
                  this.$tab.reLaunch('/pages/main/order/result/success?orderId='+this.orderId+'&status=cancel')
                }
							})
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});


			},
		}
	}
</script>

<style lang="scss">
	page {
		box-sizing: border-box;
		padding: 0 30rpx;
		padding-bottom: 200rpx;
	}

	.cause-box {
		width: 690rpx;
		background: #FFFFFF;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin-top: 22rpx;

		.item-box {
			font-family: PingFang SC, PingFang SC;
			font-weight: bold;
			font-size: 28rpx;
			color: #000000;
			font-style: normal;
			text-transform: none;
			padding: 30rpx 36rpx 30rpx 30rpx;
			border-bottom: 2rpx solid rgba(112, 112, 112, 0.1);

			.select-img {
				width: 32rpx;
				height: 32rpx;
			}
		}
	}

	.main-title {
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 40rpx;
		margin-top: 50rpx;
		margin-bottom: 6rpx;
		color: #000000;
		text-align: left;
		font-style: normal;
		text-transform: none;
	}

	.tip-title {
		font-family: PingFang SC, PingFang SC;
		font-weight: 500;
		font-size: 24rpx;
		color: #595959;
		text-align: left;
		font-style: normal;
		text-transform: none;
	}

	.bottom-box {
		position: fixed;
		left: 0;
		bottom: 0;
		width: 750rpx;
		height: 100rpx;
		background: #FFFFFF;
		box-sizing: content-box;
		box-shadow: 0rpx -2rpx 0rpx 2rpx rgba(112, 112, 112, 0.16);
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		padding-bottom: constant(safe-area-inset-bottom); // 兼容 IOS<11.2
		padding-bottom: env(safe-area-inset-bottom); // 兼容 IOS>11.2

		.btn {
			width: 690rpx;
			height: 88rpx;
			line-height: 88rpx;
			background: #FF7947;
			border-radius: 20rpx 20rpx 20rpx 20rpx;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 30rpx;
			margin-top: 6rpx;
			color: #FFFFFF;
			text-align: center;
			font-style: normal;
			text-transform: none;
		}
	}
</style>
